#!/usr/bin/env python
# -*- coding: utf-8 -*-


import pymysql

db = pymysql.connect(
    host="127.0.0.1",
    user='root',
    password='123456',
    database='sql_prac',
    port=3306
)

cursor = db.cursor()

sql = """
select * from question
"""

# cursor.execute(sql)
# while True:
#     result = cursor.fetchone()
#     if not result:
#         break
#     print(result)
# db.close()


# 使用fetchall，一次性可以把所有满足条件的数据都取出来
# sql = """
# select * from question
# """
# cursor.execute(sql)
# results = cursor.fetchall()
# for result in results:
#     print(result)
# db.close()


# 使用fetchmany，指定获取多少条数据
sql = """
select * from question
"""
cursor.execute(sql)
results = cursor.fetchmany(5)
for result in results:
    print(result)
db.close()
